package org.beetl.json;

import java.io.IOException;
import java.util.List;
import java.util.TreeSet;

import org.beetl.json.action.IValueAction;
import org.beetl.json.loc.IndexLocation;
import org.beetl.json.loc.IndexLocationList;

public abstract class OutputNode  {

	//待处理的序列化策略
	protected String inHeritedPolicy = JsonTool.EMPTY_POLICY;
	//本节点的Action
	protected  TreeSet<IValueAction>  valueActions =  new TreeSet(new ActionComparator<IValueAction>());
	protected boolean hasValueAction = false ;
	//是否忽略本节点
	protected boolean ignore = false ;
	//索引位置
	protected IndexLocationList indexLocationList = null;
	public    abstract void render(OutputNodeKey fileld,Object obj, JsonWriter w) throws IOException  ;
	

	/** 增加Action
	 * @param list
	 */
	public abstract void addActionIfMatchLocations(List<Location> list,JsonTool tool) ;
	

	public String getInHeritedPolicy() {
		return inHeritedPolicy;
	}

	/** 设置继承的序列化策略，对于Java Node来说，无法设置
	 * @param inHeritedPolicy
	 */
	public void setInHeritedPolicy(String inHeritedPolicy) {
		this.inHeritedPolicy = inHeritedPolicy;
	}

	public boolean isIgnore() {
		return ignore;
	}

	public void setIgnore(boolean ignore) {
		this.ignore = ignore;
	}

	public IndexLocationList getIndexLocations() {
		return indexLocationList;
	}

	public void addIndexLocations(IndexLocation l){
		if(this.indexLocationList ==null){
			indexLocationList = new IndexLocationList();
			
		}
		indexLocationList.addIndexLocation(l);
	}

	public void addInheritedPolicy(String policy){
		if(this.inHeritedPolicy==JsonTool.EMPTY_POLICY){
			this.inHeritedPolicy = policy;
		}else{
			this.inHeritedPolicy = this.inHeritedPolicy+","+policy;
		}
	}

	

}
